const path=require('path');
const fs=require('fs');
const render=require('./render');
const file=require('./file');


module.exports=async (ctx,staticPath)=>{
    let reqPath=path.join(staticPath,ctx.url);
    console.log('reqPath:',reqPath);

    let exist=fs.existsSync(reqPath);

    let content='';

    if(!exist){
        content='404!!!';
    }else{
        let stat=fs.statSync(reqPath);

        if(stat.isDirectory()){
            content=render(ctx.url,reqPath);
        }else{
            content=await file(reqPath);
        }
    }
    return content;
};